<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="zh-cn" style="height: 100%">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title><?=VIEW_TITLE?></title>
    <link href="<?php echo base_url('/assets/bs/'); ?>css/bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url('/assets/css/'); ?>my_common.css" rel="stylesheet">
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
</head>
<body>
<?php
$this->load->view('admin_header.php');
?>
<div class="container">
    <div id="main_div" style="max-width: 720px;margin: auto;">
        <ul id="myTab" class="nav nav-pills" role="tablist">
            <li role="presentation" class="active" onclick="getTiXian(0);"><a href="#" data-toggle="tab">提现申请</a></li>
            <li role="presentation" onclick="getTiXian(1);"><a href="#" data-toggle="tab">提现详情</a></li>
            <li role="presentation" onclick="getGaoFei();"><a href="#" data-toggle="tab">稿费详情</a></li>
        </ul>
        <div id="scroll_div" style="overflow-y: auto;overflow-x: hidden;margin-top: 20px;">
            <table id="my_table" class="table table-striped" style="margin-bottom: 0;">
            </table>
        </div>
        <div id="sum" style="text-align: right;">
        </div>
    </div>

</div>
<?php
$this->load->view('footer.php');
?>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="<?php echo base_url('/assets/bs/'); ?>js/bootstrap.min.js"></script>
<script>
    var w_width = document.documentElement.clientWidth;
    var w_height = document.documentElement.clientHeight;
    var scroll_div_height = w_height - 300;
    $('#scroll_div').height(scroll_div_height + 'px');
    getTiXian(0);
    function getTiXian(type) {
        $.ajax({
            url: '<?php echo site_url('/Administrator/getTiXianJson')?>',
            type: 'post',
            dataType: 'json',
            data: {
                type: type
            },
            success: function (data) {
                var length = data.length;
                var html = '';

                html += '<tr><th>用户名</th><th>金额(人民币)</th><th>支付宝账号</th><th>状态</th></tr>';
                for (var i = 0; i < length; i++) {
                    html += '<tr id="pay_' + data[i]['id'] + '">';
                    html += '<td>' + data[i]['username'] + '</td>';
                    html += '<td>' + data[i]['money'] / 10 + '</td>';
                    html += '<td>' + data[i]['account'] + '</td>';
                    html += '<td>';
                    if (type == 0) {
                        html += '<button id="pay_btn_' + data[i]['id'] + '" class="btn btn-danger btn-xs" onclick="doPay(' + data[i]['id'] + ')">待付款</button>';
                    } else {
                        html += '<button id="pay_btn_' + data[i]['id'] + '" class="btn btn-success btn-xs"">已付款</button>';

                    }
                    html += '</td></tr>';
                }
                $("#my_table").empty();
                $("#my_table").append(html);
                sum(type);
            }
        });
    }

    function getGaoFei() {
        $.ajax({
            url: '<?php echo site_url('/Administrator/getGaoFeiJson')?>',
            type: 'post',
            dataType: 'json',
            data: {},
            success: function (data) {
                var length = data.length;
                var html = '';

                html += '<tr><th>用户名</th><th>字数</th><th>稿费(人民币)</th><th>时间</th></tr>';
                for (var i = 0; i < length; i++) {
                    html += '<tr id="pay_' + data[i]['id'] + '">';
                    html += '<td>' + data[i]['username'] + '</td>';
                    html += '<td>' + data[i]['text_number'] + '</td>';
                    html += '<td>' + data[i]['money'] / 10+ '</td>';
                    html += '<td>' + data[i]['creat_time'] + '</td>';
                    html += '</tr>';
                }
                $("#my_table").empty();
                $("#my_table").append(html);
                sum(2);
            }
        });
    }

    function doPay(id) {
        $.ajax({
            url: '<?php echo site_url('/Administrator/doPay')?>',
            type: 'post',
            dataType: 'json',
            data: {
                id: id
            },
            success: function (data) {
                if (data == 1) {
                    $("#pay_btn_" + id).attr('class', 'btn btn-success btn-xs');
                    $("#pay_btn_" + id).text('已付款');
                    setTimeout(function () {
                        $("#pay_" + id).hide();
                    }, 1000);
                } else {
                    alert('Error : 更改失败,请刷新重试!');
                }
            }
        });
    }

    function sum(type) {
        if (type == 0) {
            $('#sum').empty();
        } else if (type == 1) {
            getTiXianSum();
        } else{
            getGaoFeiSum();
        }
    }

    function getTiXianSum() {
        $.ajax({
            url: '<?php echo site_url('/Administrator/getTiXianSum')?>',
            type: 'post',
            dataType: 'json',
            data: {},
            success: function (data) {
                $("#sum").text("总计提现:" + data / 10);
            }
        });
    }

    function getGaoFeiSum() {
        $.ajax({
            url: '<?php echo site_url('/Administrator/getGaoFeiSum')?>',
            type: 'post',
            dataType: 'json',
            data: {},
            success: function (data) {
                $("#sum").text("总计稿费:" + data / 10);
            }
        });
    }

    //        $(function () { $("[data-toggle='tooltip']").tooltip(); });
    //        $(function () { $("[data-toggle='popover']").popover(); });

    //    $('#help').tooltip();
    //    function createCode() {
    //        $.ajax({
    //            url: '<?php //echo site_url('/Administrator/createCode')?>//',
    //            type: 'post',
    //            dataType: 'json',
    //            data: {},
    //            success: function (data) {
    //                if(data == 'success'){
    //                    getCode();
    //                }else{
    //                    alert(data);
    //                }
    //            }
    //        });
    //    }
    //
    //    function getCode() {
    //        $.ajax({
    //            url: '<?php //echo site_url('/Administrator/getCodeJson')?>//',
    //            type: 'post',
    //            dataType: 'json',
    //            data: {},
    //            success: function (data) {
    //                var len = data.length;
    //                var html = '';
    //                for (var i = 0; i < len; i++) {
    //                    html += '<tr class="remove"><td>' + data[i]['code'] + '</td></tr>';
    //                }
    //                $('tr').remove('.remove');
    //                $('#code').append(html);
    //            }
    //        });
    //    }
    //    getCode();
</script>
</body>
</html>